import axios from 'axios'

class Axios {
    constructor(){
        this.axiosInstance=axios.create({
            baseURL:"http://127.0.0.1:8888/api/private/v1"
        })
        this.addRequestInterceptor()
    }
    //相应拦截器
    addRequestInterceptor(){
        this.axiosInstance.interceptors.request.use((config)=>{
            const token = sessionStorage.getItem('TOKEN')
            token && (config.headers.Authorization=token)
            return config;
        })
    }
    get(url, data={}) {
        return data ? this.axiosInstance.get(url, { params: data }) : this.axiosInstance.get(url)
    }
    post(url, data = {}) {
        return this.axiosInstance.post(url, data)
    }
    put(url) {
        return this.axiosInstance.put(url)
    }
}
const AppAxios = new Axios()
export default AppAxios